<template>
  <el-menu
    active-text-color="#ffd04b"
    background-color="#545c64"
    class="el-menu-vertical-demo"
    default-active="2"
    text-color="#fff"
    :collapse="!$store.state.HomeModule.navBool"
    @open="handleOpen"
    @close="handleClose"
    router
  >
    <template v-for="v in router.options.routes[1].children" :key="v.path">
      <!-- 带下拉的导航栏 -->
      <el-sub-menu :index="v.path" v-if="v.children">
        <template #title>
          <el-icon><component :is="v.meta.icon"></component></el-icon>
          <span>{{ v.meta.title }}</span>
        </template>
        <el-menu-item-group v-for="value in v.children" :key="value.path">
          <el-menu-item :index="value.path">{{
            value.meta.title
          }}</el-menu-item>
        </el-menu-item-group>
        <!-- <el-menu-item-group title="Group Two">
        <el-menu-item index="1-3">item three</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title>item four</template>
        <el-menu-item index="1-4-1">item one</el-menu-item>
      </el-sub-menu> -->
      </el-sub-menu>
      <!-- 带下拉的导航栏 -->
      <!-- 不带下拉的导航栏 -->
      <el-menu-item :index="v.path" v-else>
        <el-icon><component :is="v.meta.icon"></component></el-icon>
        <span>{{ v.meta.title }}</span>
      </el-menu-item>
      <!-- 不带下拉的导航栏 -->
    </template>
  </el-menu>
</template>

<script lang="ts" setup>
import { onMounted } from "vue";
import {
  Menu as IconMenu,
  Coin,
  Document,
  TrendCharts,
  Van,
} from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
let router = useRouter();
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
onMounted(() => {
  console.log("获取路由规则", router.options.routes[1].children);
});
</script>

<style scoped lang="scss"></style>
